package cn.microservicedemo.productclient.controller;

import cn.microservicedemo.productclient.Client.ProductServiceClient;
import cn.microservicedemo.productclient.model.Product;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@AllArgsConstructor
@RestController
@Slf4j
public class ProductServiceClientController {

    @Qualifier("cn.microservicedemo.productclient.Client.ProductServiceClient")
    @Autowired
    private final ProductServiceClient prodServiceClient;
    /**
     * 根据商品id查询商品
     */
    @GetMapping("/findByProductId/{productId}")
    public Product findByProductId(@PathVariable Long productId) {
        Product product = prodServiceClient.findByProductId(productId);
        log.info("--------------In client  findByProductId---------------------");
        return product;
    }
    /**
     * 查询所有商品
     */
    @GetMapping("/queryAllProduct")
    public List<Product> findByProductId() {
        List<Product> productList = prodServiceClient.queryAllProduct();
        log.info("--------------In client  queryAllProduct---------------------");
        return productList;
    }
    /**
     * 新增商品
     */
    @PostMapping("/addNewProduct")
    public boolean addNewProduct(@RequestBody Product product){
        boolean result = prodServiceClient.addNewProduct(product);
        log.info("-------------In client   addNewProduct--------------------");
        return result;
    }
    /**
     * 删除商品
     */
    @DeleteMapping("/deleteProduct/{productId}")
    public boolean deleteProduct(@PathVariable Long productId){
        boolean result = prodServiceClient.deleteProduct(productId);
        log.info("-------------In client   deleteProduct--------------------");
        return result;
    }

    /**
     * 修改商品
     */
    @PutMapping("/updateProduct")
    public boolean updateProduct(@RequestBody Product product){
        boolean result = prodServiceClient.updateProduct(product);
        log.info("-------------In client   updateProduct--------------------");
        return result;
    }
}
